package com.deyou.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.deyou.AppManager;
import com.deyou.MainActivity;
import com.deyou.R;
import com.deyou.base.BaseActivity;
import com.deyou.util.AndroidUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class PayResultActivity extends BaseActivity {

    @BindView(R.id.iv_left_back)
    ImageView ivLeftBack;
    @BindView(R.id.tv_mid_title)
    TextView tvMidTitle;
    @BindView(R.id.iv_pay_result)
    ImageView ivPayResult;
    @BindView(R.id.tv_pay_result)
    TextView tvPayResult;
    @BindView(R.id.btn_back_home)
    TextView btnBackHome;
    @BindView(R.id.btn_to_order)
    TextView btnToOrder;
    @BindView(R.id.btn_pay_result)
    TextView btnPayResult;

    private int payStatus = 0; // 1 - 支付成功; 2 - 支付失败;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alipay_result);
        ButterKnife.bind(this);
        initData();
        initView();
    }

    private void initData() {
        payStatus = getIntent().getExtras().getInt("payStatus");
    }

    private void initView() {
        if (1 == payStatus) {
            tvMidTitle.setText("支付成功");
            tvPayResult.setText("恭喜！您的订单已支付成功！");
            btnPayResult.setText("知道了");
            ivPayResult.setImageResource(R.drawable.ic_pay_success);
        } else {
            tvMidTitle.setText("支付失败");
            tvPayResult.setText("不好！您的订单支付出现异常啦！");
            btnPayResult.setText("再试试");
            ivPayResult.setImageResource(R.drawable.ic_pay_fail);
        }
    }

    @OnClick({R.id.iv_left_back, R.id.btn_back_home, R.id.btn_to_order, R.id.btn_pay_result})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_left_back:
                AndroidUtils.startNextActivity(PayResultActivity.this, MyTravelListActivity.class, null, false);
                AppManager.getAppManager().finishAllActivity(MainActivity.class);
                break;
            case R.id.btn_back_home:
                AppManager.getAppManager().finishAllActivity(MainActivity.class);
//                AndroidUtils.startNextActivity(PayResultActivity.this, MyTravelListActivity.class, null, false);
                break;
            case R.id.btn_to_order:
                AndroidUtils.startNextActivity(PayResultActivity.this, MyTravelListActivity.class, null, false);
                AppManager.getAppManager().finishAllActivity(MainActivity.class);
                break;
            case R.id.btn_pay_result:
                if (1 == payStatus) {
                    AppManager.getAppManager().addActivity(PayResultActivity.this);
                } else {
                    AndroidUtils.startNextActivity(PayResultActivity.this, MyTravelListActivity.class, null, false);
                }
                AppManager.getAppManager().finishAllActivity(MainActivity.class);
                break;
        }
    }
}
